﻿/*
 * 作者: 谢中涞,博客园:http://www.cnblogs.com/xie-zhonglai
 * 欢迎转载,但请保留出处
 * */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;

namespace Xiezl.Common.Repositorys
{
    /// <summary>
    ///  仓储模型基本接口,提供基本的数据库增删改查接口
    /// </summary>
    /// <typeparam name="TEntity">实体类型</typeparam>
    public interface IRepository<TEntity> : IDisposable where TEntity : class
    {
        /// <summary>
        /// 获取所有数据
        /// </summary>
        /// <returns></returns>
        IQueryable<TEntity> Get();

        /// <summary>
        /// 根据指定的查询条件
        /// </summary>
        /// <param name="expression">查询条件</param>
        /// <returns></returns>
        IQueryable<TEntity> Get(Expression<Func<TEntity, bool>> expression);

        /// <summary>
        /// 根据指定条件查询分页数据
        /// </summary>
        /// <typeparam name="TOrderType">排序类型</typeparam>
        /// <param name="expression">查询条件</param>
        /// <param name="orderPropertyName">排序字段</param>
        /// <param name="isAscOrder">是否是升序查询</param>
        /// <param name="pgIndex"></param>
        /// <param name="pgSize"></param>
        /// <param name="total">总记录数</param>
        /// <returns></returns>
        [Obsolete("建议使用 IQueryable<TEntity> Get(EFQueryParam<TEntity> queryParam, out int total) 方法")]
        IQueryable<TEntity> Get(Expression<Func<TEntity, bool>> expression,
            string orderPropertyName, bool isAscending,
            int pgIndex, int pgSize, out int total);

        /// <summary>
        /// 根据指定条件查询数据
        /// </summary>
        /// <param name="queryParam">查询条件</param>
        /// <param name="total">符合条件的总记录数,该返回值在参数IsPagingQuery为true值时才有效</param>
        /// <returns></returns>
        IQueryable<TEntity> Get(EFQueryParam<TEntity> queryParam, out int total);

        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="entity"></param>
        void Add(TEntity entity);
        /// <summary>
        /// 根据具体实体删除
        /// </summary>
        /// <param name="entity"></param>
        void Delete(TEntity entity);

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="entity"></param>
        void Update(TEntity entity);

        /// <summary>
        /// 根据主键获取
        /// </summary>
        /// <param name="id">主键Id值</param>
        /// <returns></returns>
        TEntity Get(params object[] ids);

        /// <summary>
        /// 根据主键删除
        /// </summary>
        /// <param name="entity">主键Id值</param>
        void Delete(params object[] ids);

        /// <summary>
        /// 保存数据修改
        /// </summary>
        void SaveDbChange();

    }

    /// <summary>
    ///  仓储模型基本接口,提供基本的数据库增删改查接口
    /// </summary>
    /// <typeparam name="TEntity">实体类型</typeparam>
    /// <typeparam name="TPkType">实体主键类型</typeparam>
    public interface IRepository<TEntity, TPkType> : IRepository<TEntity>
         where TEntity : class,IEntity<TPkType>
    {

        /// <summary>
        /// 根据主键获取
        /// </summary>
        /// <param name="id">主键Id值</param>
        /// <returns></returns>
        TEntity Get(TPkType id);

        /// <summary>
        /// 根据主键删除
        /// </summary>
        /// <param name="id">主键Id值</param>
        void Delete(TPkType id);


    }
}
